<cpanel include="../../config.php">

<?

/***************************************************************************
 *                                 bandwidth.php
 *                            -------------------
 *   Begin                : Sunday, May 15, 2005
 *   Copyright            : (C) 2005 Point and Code
 *   Domain               : http://www.pointandcode.com/
 *   Email                : support@pointandcode.com
 *   Version              : 1.0.0
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

$html_root_path = '../../';
include $root_path.'common.php';
$page_title = $lang['bandwidth'];
include $root_path.'page_header.php';


$template->set_filenames(array(
	'body' => $root_path.$template_path.'stats/bandwidth.tpl')
);


//
// Get the info from cpanel
//
$bandwidth_bar = <<<EOFpacman
<cpanel Stats="bwbar()">
EOFpacman;

$temp = explode('</td><td>', $bandwidth_bar);
$temp = explode('% used</td>', $temp[1]);
$bandwidth_percentage = $temp[0];


$bandwidth_header = <<<EOFpacman
<cpanel Bandwidth="displaymainbwheader()">
EOFpacman;

$temp = explode('<IMG SRC="', $bandwidth_header);
$temp2 = explode('" WIDTH=', $temp[1]);
$bandwidth_img_today = $temp2[0];
$temp2 = explode('" WIDTH=', $temp[2]);
$bandwidth_img_year = $temp2[0];


$bandwidth_main = <<<EOFpacman
<cpanel Stats="showbandwidth()">
EOFpacman;

$bandwidth_split = explode('<fieldset>', $bandwidth_main);

foreach ($bandwidth_split as $row)
{
	if (trim($row) != '')
	{
		$temp = explode('<legend><b>', $row);
		$temp2 = explode('</b>', $temp[1]);
		$title = $temp2[0];
		$temp = explode(' ', $title);
		$month = $temp[0];
		$year = $temp[1];
		
		$domain_junk = explode('<tr><td class=bwtableb><img src="', $row);
		$i = 0;
		foreach ($domain_junk as $line)
		{
			if ($i != 0)
			{
				//
				// And the cpanel HTML code goes "boom!!!".
				//
				$temp = explode('" align=', $line);
				$domain_data[$i]['legend_img'] = $temp[0];
				
				$temp = explode('&domain=', $line);
				$temp2 = explode('&target=', $temp[1]);
				
				$domain_data[$i]['domain'] = $temp2[0];
				$temp3 = explode('">', $temp2[1]);
				$domain_data[$i]['target'] = $temp3[0];
				
				$temp = explode('class=bwtableb>', $temp3[1]);
				
				// Check and see if this is a subdomain, or a domain. Taking advantage of cpanel <b>-ing domains, but not subdomains.
				$temp2 = explode('</a>', $temp[0]);
				if (strpos($temp2[0], '<b>') === false)
				{
					$domain_data[$i]['sub'] = 1;
				} else {
					$domain_data[$i]['sub'] = 0;
				};
				
				$temp = explode('</td></tr>', $temp[1]);
				$domain_data[$i]['bandwidth'] = $temp[0];
			
				$temp = explode('Total', $line);
				$temp = explode('<td class=bwtable>', $temp[1]);
				$temp = explode('</td>', $temp[1]);
				$total_bandwidth = $temp[0];
				
				
				
				// Now get the pie chart. Note that this will only work in the final iteration of this loop (if it gets junk from the others, then that'll be overwritten anyhow). There's probably a better way to code this...
				$temp = explode('<td width=25% align=center><img', $line);
				$temp2 = explode('name=', $temp[1]);
				$temp2 = explode(' src="', $temp2[1]);
				$pie_name = $temp2[0];
				$temp = explode('src="', $temp[1]);
				$temp = explode('"', $temp[1]);
				$pie_url = $temp[0];
				$temp = explode('onMouseOver="', $temp2[1]);
				$temp = explode('">', $temp[1]);
				$pie_onClick = $temp[0];
				
			};
			$i++;
		};
		$template->assign_block_vars('monthly_bandwidth_row', array(
			'TITLE' => $title,
			'MONTH' => $month,
			'YEAR' => $year,
			'TOTAL_BANDWIDTH' => $total_bandwidth,
			
			'PIE_NAME' => $pie_name,
			'I_PIE' => $pie_url,
			'PIE_ONCLICK' => $pie_onClick,
			
			'BANDWIDTH' => $row,
		));
		
		for ($j = 1; $j < $i; $j++)
		{
			$template->assign_block_vars('monthly_bandwidth_row.domains_row', array(
				'I_LEGEND' => $domain_data[$j]['legend_img'],
				'DOMAIN' => $domain_data[$j]['domain'],
				'BANDWIDTH' => $domain_data[$j]['bandwidth'],
				
				'U_DETAIL' => (($domain_data[$j]['sub'] == 0) ? 'bandwidth_detail.php' : 'bandwidth_sub_detail.php').'?mon='.$month.'&year='.$year.'&domain='.$domain_data[$j]['domain'].'&target='.$domain_data[$j]['target'],
			));
		};
		
	};
};


$template->assign_vars(array(
	'BANDWIDTH_PERCENTAGE' => $bandwidth_percentage,
	'BANDWIDTH_IMG_TODAY' => $bandwidth_img_today,
	'BANDWIDTH_IMG_YEAR' => $bandwidth_img_year,
	
	'BANDWIDTH_MAIN' => $bandwidth_main,

	'L_BANDWIDTH' => $lang['bandwidth'],
));

//
// Woohoo! All done!
//
$template->pparse('body');

include $root_path.'page_tail.php';


?>